package com.itheima.reggie.config;

import com.itheima.reggie.exception.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;


@Slf4j
//@Configuration
public class WebMvcConfig  extends WebMvcConfigurationSupport  {
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
      //  System.out.println("开始进行静态自学映射");
       registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }
    /* 设置静态资源映射:因为springboot里默认的是stataic和Thymelate里下的页面*/

    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        System.out.println("消息转化器");
        //新建一个自己的消息转化器,不使用框架默认的 如@RequestBody使用的就是框架默认的
        MappingJackson2HttpMessageConverter messageConverter=new MappingJackson2HttpMessageConverter();
        messageConverter.setObjectMapper(new JacksonObjectMapper());
        //将自己添加的消息转化器追加到mvc框架中消息转化器集合中,0是代表第一个，让消息转化器第一个使用我们定义的
        converters.add(0,messageConverter);

    }
}
